//定义一个存放相关GISID的JSON对象
var gisIdJsonArray;


function createProHtml(p,i){
	
	var html='';
    var hangClass='ul-header bg-white';
    if(i%2!=0){
      hangClass='ul-header bg-second';
    }     

    //穿跨越主键ID
	var crossId=convertObjectToString(p.CROSSID);
	// 管线名称
	var lineName = convertObjectToString(p.LINENAME);
	// 穿跨越编号
	var crossingNum = convertObjectToString(p.CROSSINGNUM);
	// 起始绝对距离
	var fromMileage = convertObjectToString(p.FROMMILEAGE);
    // 起始位置产考点
    var fromReference = convertObjectToString(p.FROMREFERENCE);
    // 起始位置产考点相对距离
    var fromReferenceDistance = convertObjectToString(p.FROMREFERENCEDISTANCE);
	// 穿跨越类型
	var crossingType = convertObjectToString(p.CROSSINGTYPE);
	//GISID
	var gisID=p.GIS_ID;

	var hhtml='<div class=\"show-ul none\">'
		+' <ul class=\"show-list\">'
		+'<li> <span class=\"s1\">统一编号:</span><span class=\"s2\"></span></li>'
		+'<li> <span class=\"s1\">管道名称:</span><span class=\"s2\"></span></li>'
		+'<li> <span class=\"s1\">穿跨越编号:</span> <span class=\"s2\"></span></li>'
		+'<li> <span class=\"s1\">穿跨越类型:</span> <span class=\"s2\"></span></li>'
		+'<li> <span class=\"s1\">穿跨越名称:</span> <span class=\"s2\"></span></li>'
		+'<li> <span class=\"s1\">穿跨越对象:</span> <span class=\"s2\"></span></li>'
		+'<li> <span class=\"s1\">穿跨越方式:</span> <span class=\"s2\"></span></li>'
		+'<li> <span class=\"s1\">起始位置绝对距离(m):</span> <span class=\"s2\"></span></li>'
		+'<li> <span class=\"s1\">起始位置最近参考点:</span> <span class=\"s2\"></span></li>'
		+'<li> <span class=\"s1\">起始位置相对参考点(m):</span> <span class=\"s2\"></span></li>'
		+'<li> <span class=\"s1\">终点位置绝对距离(m):</span> <span class=\"s2\"></span></li>'
		+'<li> <span class=\"s1\">终点位置最近参考点:</span> <span class=\"s2\"></span></li>'
		+'<li> <span class=\"s1\">终点位置相对参考点(m):</span> <span class=\"s2\"></span></li>'
		+'<li> <span class=\"s1\">穿越长度(m):</span> <span class=\"s2\"></span></li>'
		+'<li> <span class=\"s1\">管节数:</span> <span class=\"s2\"></span></li>'
		+'<li> <span class=\"s1\">材质:</span> <span class=\"s2\"></span></li>'
		+'<li> <span class=\"s1\">壁厚(mm):</span> <span class=\"s2\"></span></li>'
		+'<li> <span class=\"s1\">稳管措施:</span> <span class=\"s2\"></span></li>'
		+'<li> <span class=\"s1\">是否有管套:</span> <span class=\"s2\"></span></li>'
		+'<li> <span class=\"s1\">防护层材料:</span> <span class=\"s2\"></span></li>'
		+'<li> <span class=\"s1\">防护层厚度:</span> <span class=\"s2\"></span></li>'
		+'<li> <span class=\"s1\">竣工资料编号:</span> <span class=\"s2\"></span></li>'
		+'<li> <span class=\"s1\">施工单位:</span> <span class=\"s2\"></span></li>'
		+'<li> <span class=\"s1\">监理单位:</span> <span class=\"s2\"></span></li>'
		+'<li> <span class=\"s1\">检测单位:</span> <span class=\"s2\"></span></li>'
		+'<li> <span class=\"s1\">记录人:</span> <span class=\"s2\"></span></li>'
		+'<li> <span class=\"s1\">记录时间:</span> <span class=\"s2\"></span></li>'
		+'<li class=\"last-li\"><span class=\"s1\">备注:</span><span class=\"s2\"><textarea placeholder=\"备注描述\"></textarea></span></li>'
		+'</ul></div></div>';

	var map='<input type="hidden" name="gisHiddenName" value="'+gisID+'"/>';

	html += '<div class=\"info-tr\"><ul class=\"ul-header '+ hangClass+ '\">' +
        '<li class="w20">'+ lineName+ '</li>' +
//        '<li class="w10">'+ crossingNum+ '</li>' +
        '<li class="w20" style="width: 14%">'+ fromMileage+ '</li>' +
        '<li class="w20" style="width: 16%">'+ fromReference+ '</li>' +
        '<li class="w10" style="width: 17%">'+ fromReferenceDistance+ '</li>' +
        '<li class="w10 no-right"><em class="xq-icon" id="'+crossId+'"></em></li></ul>'
		+''+hhtml+''+map+'';
	
	 return html;
	
}

/* 日期格式化 */
Date.prototype.Format = function(format){ 
	var o = { 
	"M+" : this.getMonth()+1, //month 
	"d+" : this.getDate(), //day 
	"h+" : this.getHours(), //hour 
	"m+" : this.getMinutes(), //minute 
	"s+" : this.getSeconds(), //second 
	"q+" : Math.floor((this.getMonth()+3)/3), //quarter 
	"S" : this.getMilliseconds() //millisecond 
	} 

	if(/(y+)/.test(format)) { 
	format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); 
	} 

	for(var k in o) { 
	if(new RegExp("("+ k +")").test(format)) { 
	format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length)); 
	} 
	} 
	return format; 
	} 

//查询穿跨越
function getCrossClick(){

    var pagePath = $("#pagePath").val();

    var lineId = $("#lineDiv").children().attr("id");
    var segmentId = $("#segmentDiv").children().attr("id");
    var startMileage = $("#startMileage").val();
    var endMileage = $("#endMileage").val();
    if(lineId == "lineAll" || lineId == "" || lineId == undefined){
        lineId = "";
    }
    if(segmentId == "segmentAll" || segmentId == "" || segmentId == undefined){
        segmentId = "";
    }
    if (startMileage == null || startMileage == "") {
        startMileage = 0;
    }
    if (endMileage == null || endMileage == "") {
        endMileage = 0;
    }

	//给隐藏表单域赋值
	$("#lineHiddenId").val(lineId);
	$("#segmentHiddenId").val(segmentId);
	$("#startMileHiddenId").val(startMileage);
	$("#endMileHiddenId").val(endMileage);

	var data={"pipeLineId":$("#lineHiddenId").val(),"pipeSegmentId":$("#segmentHiddenId").val(),
            "startMileage":$("#startMileHiddenId").val(),
            "endMileage":$("#endMileHiddenId").val()};

	var b=window.sessionStorage;
	
	b.removeItem("mapData");
	
	b.setItem("mapData", JSON.stringify(data));
	
	var map={"fillDiv":"#searchBody","url":""+pagePath+"/basedata/pipeController/getCross.json"};
	
	searchPage(map,data);
}

//导出穿跨越详情Excel
function pipeCrossDonload() {

    var lineId = $("#lineDiv").children().attr("id");
    var segmentId = $("#segmentDiv").children().attr("id");
    var startMileage = $("#startMileage").val();
    var endMileage = $("#endMileage").val();
    if(lineId == "lineAll" || lineId == "" || lineId == undefined){
        lineId = "";
    }
    if(segmentId == "segmentAll" || segmentId == "" || segmentId == undefined){
        segmentId = "";
    }
	if (startMileage == null || startMileage == "") {
		startMileage = 0;
	}
	if (endMileage == null || endMileage == "") {
		endMileage = 0;
	}

    var pagePath = $("#pagePath").val();
    var actionPath = pagePath+ "/basedata/pipeController/getCross/getExcel.html";
	$("#pipeCrossForm").attr("action", actionPath);

	$("#lineId").val(lineId);
	$("#segmentId").val(segmentId);
	$("#startMileage").val(startMileage);
	$("#endMileage").val(endMileage);

	$("#pipeCrossForm").submit();
}

//详情点击事件
function crossDetails(id,t){
    var pagePath = $("#pagePath").val();
	var url= pagePath+"/basedata/pipeController/details/getCross/"+id+".json"
	$.ajax({
        type : "get",
        url : url,
        dataType : "json",
        success:function(data){
            var code = data.result.code;
            var obj=data.result.obj;
            if(code=='0000000000' && ""!=obj && null!=obj){
            	//统一编号
            	var Code="-";
            	if(""!=obj&&null!=obj&&""!=obj.CODE&&null!=obj.CODE){
                    Code=obj.CODE
                }
            	
                //注入统一编号
                t.parents('.ul-header').next().find('.show-list li').eq(0).find('span').eq(1).html(Code);
                
                //管线名称
                var lineName="-";
                if(""!=obj&&null!=obj&&""!=obj.LINENAME&&null!=obj.LINENAME){
                    lineName=obj.LINENAME;
                }

                //注入管线名称
                t.parents('.ul-header').next().find('.show-list li').eq(1).find('span').eq(1).html(lineName);

                //管段名称
                var segmentName="-";
                if(""!=obj&&null!=obj&&""!=obj.SEGMENTNAME&&null!=obj.SEGMENTNAME){
                    segmentName=obj.SEGMENTNAME;
                }
                //注入管段名称
                t.parents('.ul-header').next().find('.show-list li').eq(2).find('span').eq(1).html(segmentName);

                //穿跨越编号
                var crossNum="-";
                if(""!=obj&&null!=obj&&""!=obj.CROSSINGNUM&&null!=obj.CROSSINGNUM){
                    crossNum=obj.CROSSINGNUM;
                }

                //注入穿跨越编号
                t.parents('.ul-header').next().find('.show-list li').eq(3).find('span').eq(1).html(crossNum);

                //穿跨越类型
                var crossType="-";
                if(""!=obj&&null!=obj&&""!=obj.CROSSINGTYPE&&null!=obj.CROSSINGTYPE){
                    crossType=obj.CROSSINGTYPE;
                }
                //注入穿跨越类型
                t.parents('.ul-header').next().find('.show-list li').eq(4).find('span').eq(1).html(crossType);


                //穿跨越名称
                var crossName="-";
                if(""!=obj&&null!=obj&&""!=obj.CROSSINGNAME&&null!=obj.CROSSINGNAME){
                    crossName=obj.CROSSINGNAME;
                }
                //注入穿跨越名称
                t.parents('.ul-header').next().find('.show-list li').eq(5).find('span').eq(1).html(crossName);


                //穿跨越对象
                var crossingTarget="-";
                if(""!=obj&&null!=obj&&""!=obj.CROSSINGTARGET&&null!=obj.CROSSINGTARGET){
                    crossingTarget=obj.CROSSINGTARGET;
                }
                //注入穿跨越对象
                t.parents('.ul-header').next().find('.show-list li').eq(6).find('span').eq(1).html(crossingTarget);

                //穿跨越方式
                var crossingMethod="-";
                if(""!=obj&&null!=obj&&""!=obj.CROSSINGMETHOD&&null!=obj.CROSSINGMETHOD){
                    crossingMethod=obj.CROSSINGMETHOD;
                }
                //注入穿跨越 方式
                t.parents('.ul-header').next().find('.show-list li').eq(7).find('span').eq(1).html(crossingMethod);

                //起始点绝对距离
                var startMileage="-";
                if(""!=obj&&null!=obj&&""!=obj.STARTMILEAGE&&null!=obj.STARTMILEAGE){
                    startMileage=obj.STARTMILEAGE;
                }
                //注入起始点绝对距离
                t.parents('.ul-header').next().find('.show-list li').eq(8).find('span').eq(1).html(startMileage);


                //心烦，下面全部不用驼峰原则


                //起始点最近参考距离
                var STARTSIGNNUM="-";
                if(""!=obj&&null!=obj&&""!=obj.STARTSIGNNUM&&null!=obj.STARTSIGNNUM){
                    STARTSIGNNUM=obj.STARTSIGNNUM;
                }
                //注入起始点最近参考距离
                t.parents('.ul-header').next().find('.show-list li').eq(9).find('span').eq(1).html(STARTSIGNNUM);

                //最近参考点相对最近参考点距离
                var STARTREFERENCEDISTANCE="-";
                if(""!=obj&&null!=obj&&""!=obj.STARTREFERENCEDISTANCE&&null!=obj.STARTREFERENCEDISTANCE){
                    STARTREFERENCEDISTANCE=obj.STARTREFERENCEDISTANCE;
                }
                //注入最近参考点相对最近参考点距离
                t.parents('.ul-header').next().find('.show-list li').eq(10).find('span').eq(1).html(STARTREFERENCEDISTANCE);


                //终点绝对里程
                var ENDMILEAGE="-";
                if(""!=obj&&null!=obj&&""!=obj.ENDMILEAGE&&null!=obj.ENDMILEAGE){
                    ENDMILEAGE=obj.ENDMILEAGE;
                }

                //注入终点绝对里
                t.parents('.ul-header').next().find('.show-list li').eq(11).find('span').eq(1).html(ENDMILEAGE);

                //终点最近参考点
                var ENDSIGNNUM="-";
                if(""!=obj&&null!=obj&&""!=obj.ENDSIGNNUM&&null!=obj.ENDSIGNNUM){
                    ENDSIGNNUM=obj.ENDSIGNNUM;
                }

                //注入终点最近参考点
                t.parents('.ul-header').next().find('.show-list li').eq(12).find('span').eq(1).html(ENDSIGNNUM);

                //终点最近参考点距离
                var ENDREFERENCEDISTANCE="-";
                if(""!=obj&&null!=obj&&""!=obj.ENDREFERENCEDISTANCE&&null!=obj.ENDREFERENCEDISTANCE){
                    ENDREFERENCEDISTANCE=obj.ENDREFERENCEDISTANCE;
                }

                //注入终点最近参考点距离
                t.parents('.ul-header').next().find('.show-list li').eq(13).find('span').eq(1).html(ENDREFERENCEDISTANCE);


                //穿越长度
                var CROSSINGLENGTH="-";
                if(""!=obj&&null!=obj&&""!=obj.CROSSINGLENGTH&&null!=obj.CROSSINGLENGTH){
                    CROSSINGLENGTH=obj.CROSSINGLENGTH;
                }

                //注入穿越长度
                t.parents('.ul-header').next().find('.show-list li').eq(14).find('span').eq(1).html(CROSSINGLENGTH);

                //管节数
                var NUM="-";
                if(""!=obj&&null!=obj&&""!=obj.NUM&&null!=obj.NUM){
                    NUM=obj.NUM;
                }

                //注入管节数
                t.parents('.ul-header').next().find('.show-list li').eq(15).find('span').eq(1).html(NUM);


                //材质
                var MATERIAL="-";
                if(""!=obj&&null!=obj&&""!=obj.MATERIAL&&null!=obj.MATERIAL){
                    MATERIAL=obj.MATERIAL;
                }

                //注入材质
                t.parents('.ul-header').next().find('.show-list li').eq(16).find('span').eq(1).html(MATERIAL);

                //壁厚
                var WALLTHICKNESS="-";
                if(""!=obj&&null!=obj&&""!=obj.WALLTHICKNESS&&null!=obj.WALLTHICKNESS){
                    WALLTHICKNESS=obj.WALLTHICKNESS;
                }

                //注入壁厚
                t.parents('.ul-header').next().find('.show-list li').eq(17).find('span').eq(1).html(WALLTHICKNESS);


                //稳管措施
                var STABLEMEASURES="-";
                if(""!=obj&&null!=obj&&""!=obj.STABLEMEASURES&&null!=obj.STABLEMEASURES){
                    STABLEMEASURES=obj.STABLEMEASURES;
                }

                //注入稳管措施数据
                t.parents('.ul-header').next().find('.show-list li').eq(18).find('span').eq(1).html(STABLEMEASURES);


                //是否有套管
                var ISSLEEVE="-";
                if(""!=obj&&null!=obj&&""!=obj.ISSLEEVE&&null!=obj.ISSLEEVE){
                    ISSLEEVE=obj.ISSLEEVE;
                }

                //注入是否有管套
                t.parents('.ul-header').next().find('.show-list li').eq(19).find('span').eq(1).html(ISSLEEVE);

                //防护层材料
                var COATINGMATERIAL="-";
                if(""!=obj&&null!=obj&&""!=obj.COATINGMATERIAL&&null!=obj.COATINGMATERIAL){
                    COATINGMATERIAL=obj.COATINGMATERIAL;
                }

                //注入防护层材料
                t.parents('.ul-header').next().find('.show-list li').eq(20).find('span').eq(1).html(COATINGMATERIAL);

                //防护层厚度
                var CONATINGTHICKNESS="-";
                if(""!=obj&&null!=obj&&""!=obj.CONATINGTHICKNESS&&null!=obj.CONATINGTHICKNESS){
                    CONATINGTHICKNESS=obj.CONATINGTHICKNESS;
                }

                //注入防护层材料
                t.parents('.ul-header').next().find('.show-list li').eq(21).find('span').eq(1).html(CONATINGTHICKNESS);

                //竣工资料编号
                var COMPLETIONDATANUM="-";
                if(""!=obj&&null!=obj&&""!=obj.COMPLETIONDATANUM&&null!=obj.COMPLETIONDATANUM){
                    COMPLETIONDATANUM=obj.COMPLETIONDATANUM;
                }

                //注入竣工资料编号
                t.parents('.ul-header').next().find('.show-list li').eq(22).find('span').eq(1).html(COMPLETIONDATANUM);

                //施工单位
                var ASSEMBLYCOMPANY="-";
                if(""!=obj&&null!=obj&&""!=obj.ASSEMBLYCOMPANY&&null!=obj.ASSEMBLYCOMPANY){
                    ASSEMBLYCOMPANY=obj.ASSEMBLYCOMPANY;
                }

                //注入施工单位
                t.parents('.ul-header').next().find('.show-list li').eq(23).find('span').eq(1).html(ASSEMBLYCOMPANY);

                //监理单位
                var INSPECTINGCOMPANY="-";
                if(""!=obj&&null!=obj&&""!=obj.INSPECTINGCOMPANY&&null!=obj.INSPECTINGCOMPANY){
                    INSPECTINGCOMPANY=obj.INSPECTINGCOMPANY;
                }

                //注入监理单位
                t.parents('.ul-header').next().find('.show-list li').eq(24).find('span').eq(1).html(INSPECTINGCOMPANY);

                //检测单位
                var TESTINGCOMPANY="-";
                if(""!=obj&&null!=obj&&""!=obj.TESTINGCOMPANY&&null!=obj.TESTINGCOMPANY){
                    TESTINGCOMPANY=obj.TESTINGCOMPANY;
                }

                //注入检测单位
                t.parents('.ul-header').next().find('.show-list li').eq(25).find('span').eq(1).html(TESTINGCOMPANY);

                //记录人
                var RECORDER="-";
                if(""!=obj&&null!=obj&&""!=obj.RECORDER&&null!=obj.RECORDER){
                    RECORDER=obj.RECORDER;
                }

                //注入记录人
                t.parents('.ul-header').next().find('.show-list li').eq(26).find('span').eq(1).html(RECORDER);

                //记录时间
                var RECORDTIME="-";
              
                if(""!=obj&&null!=obj&&""!=obj.RECORDTIME&&null!=obj.RECORDTIME  ){
     
                    RECORDTIME=	obj.RECORDTIME;
                   
                }
              
             
                //注入记录时间
                t.parents('.ul-header').next().find('.show-list li').eq(27).find('span').eq(1).html(RECORDTIME);


                //备注
                var REMARK="-";
                if(""!=obj&&null!=obj&&""!=obj.REMARK&&null!=obj.REMARK){
                    REMARK=obj.REMARK;
                  
                }
               

                //注入备注
                t.parents('.ul-header').next().find('.show-list li').eq(28).find('span').find("textarea").eq(0).html(REMARK);

            }

        }
	});
}


function convertObjectToString(obj){
    return null==obj || "" == $.trim(obj) ? "-" : obj;
}
/*function convertObjectToDate(obj){
    return null==obj || "" == $.trim(obj) ? "-" : new Date(obj).Format("yyyy-MM-dd ");
}*/





